package cn.xiehangs;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.utils.viewport.StretchViewport;

import java.util.Random;

public class ce_shi_1 extends ApplicationAdapter {
    Texture piece1,piece2,piece3,piece4,imageUp,imageDown;
    di_tu di_tu1;
    tou_zi tou_zi1;
    qi_zi qi_zi0,qi_zi1,qi_zi2,qi_zi3,qi_zi4,qi_zi5,qi_zi6,qi_zi7,qi_zi8,qi_zi9,qi_zi10,qi_zi11,qi_zi12,qi_zi13,qi_zi14,qi_zi15;
    qi_zi_group group0,group1,group2,group3;
    qi_pan_wz pan_wz;
    Stage stage;
    Button btn;
    SpriteBatch batch;
    Button.ButtonStyle style;
    int stageWidth = 1024+1024/3;
    int stageHeight = 1024;
    Random rd=new Random();
    @Override
    public void create() {
        batch = new SpriteBatch();


        di_tu1= new di_tu("飞行棋地图_红.png",1024,1024);
        //新建舞台
        stage = new Stage(new StretchViewport(stageWidth,stageHeight));
        Gdx.graphics.setWindowedMode(stageWidth,stageHeight);//设置窗口大小
        Gdx.input.setInputProcessor(stage);
        tou_zi1=new tou_zi(1024,1024*2/3,1024/3,1024/3,"tou_zi1","tou_zi");
        stage.addActor(tou_zi1);
        qi_zi0=new qi_zi("hong",0);
        qi_zi1=new qi_zi("hong",1);
        qi_zi2=new qi_zi("hong",2);
        qi_zi3=new qi_zi("hong",3);
        qi_zi4=new qi_zi("lan",4);
        qi_zi5=new qi_zi("lan",5);
        qi_zi6=new qi_zi("lan",6);
        qi_zi7=new qi_zi("lan",7);
        qi_zi8=new qi_zi("huang",8);
        qi_zi9=new qi_zi("huang",9);
        qi_zi10=new qi_zi("huang",10);
        qi_zi11=new qi_zi("huang",11);
        qi_zi12=new qi_zi("lv",12);
        qi_zi13=new qi_zi("lv",13);
        qi_zi14=new qi_zi("lv",14);
        qi_zi15=new qi_zi("lv",15);



        //下面顺序不能变，是按先后顺序绘制的
        stage.addActor(di_tu1);//添加地图
//        stage.addActor(qi_zi0);//添加棋子
//        stage.addActor(qi_zi1);
//        stage.addActor(qi_zi2);
//        stage.addActor(qi_zi3);
//        stage.addActor(qi_zi4);
//        stage.addActor(qi_zi5);
//        stage.addActor(qi_zi6);
//        stage.addActor(qi_zi7);
//        stage.addActor(qi_zi8);
//        stage.addActor(qi_zi9);
//        stage.addActor(qi_zi10);
//        stage.addActor(qi_zi11);
//        stage.addActor(qi_zi12);
//        stage.addActor(qi_zi13);
//        stage.addActor(qi_zi14);
//        stage.addActor(qi_zi15);
//        group0=new qi_zi_group(0,qi_zi0,qi_zi1,qi_zi2,qi_zi3);
//        group1=new qi_zi_group(1,qi_zi4,qi_zi5,qi_zi6,qi_zi7);
//        group2=new qi_zi_group(2,qi_zi8,qi_zi9,qi_zi10,qi_zi11);
//        group3=new qi_zi_group(3,qi_zi12,qi_zi13,qi_zi14,qi_zi15);
        group0=new qi_zi_group(0,qi_zi0,qi_zi1,qi_zi2,qi_zi3,true);
        group1=new qi_zi_group(1,qi_zi4,qi_zi5,qi_zi6,qi_zi7,true);
        group2=new qi_zi_group(2,qi_zi8,qi_zi9,qi_zi10,qi_zi11,true);
        group3=new qi_zi_group(3,qi_zi12,qi_zi13,qi_zi14,qi_zi15,true);
        qi_zi_group.tou_zi=tou_zi1;
        stage.addActor(group0);
        stage.addActor(group1);
        stage.addActor(group2);
        stage.addActor(group3);
        pan_wz=new qi_pan_wz(group0,group1,group2,group3);
        group0.number_1.setMove_step_pool(0);

        InputMultiplexer inputMultiplexer= new InputMultiplexer();//创建一个InputMultiplexer实例
        Gdx.input.setInputProcessor(inputMultiplexer);//将inputMultiplexer设置为输入处理器
        inputMultiplexer.addProcessor(stage);//添加舞台为输入处理器








    }

    @Override
    public void resize(int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    @Override
    public void render() {

        Gdx.gl.glClearColor(0.455f, 0.725f, 1.0f, 1.0f);// 设置清屏颜色
        Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);// 清屏
        batch.begin();//共享资源绘制
        batch.end();
        group0.robot();
        group1.robot();
        group2.robot();
        group3.robot();
        group0.is_win();
        group1.is_win();
        group2.is_win();
        group3.is_win();
        stage.act();//舞台动作
        stage.draw();//舞台绘制

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

        piece1.dispose();
//        piece2.dispose();
//        piece3.dispose();
//        piece4.dispose();
        stage.dispose();
        batch.dispose();

    }
}
